package com.sx.wechat.command.api;

import com.sx.core.utils.PropertyUtils;
import com.sx.core.utils.WxJsUtils;
import com.sx.core.utils.WxRequestInstance;
import com.sx.core.vo.JsonReaderResponse;
import com.sx.wechat.command.cmd.AbstractCommand;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by lihao on 2018/9/25.
 */
@Component("scan_pre")
public class Scan_pre extends AbstractCommand {
    String appId= PropertyUtils.getProperty("wx.appId");
    String url= PropertyUtils.getProperty("mobile.redirect.url");
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Override
    public Object executeApi(HttpServletRequest request, HttpServletResponse response) {
        String vr_token=(String)request.getAttribute("access_token");
        String token = WxRequestInstance.getInstance().getBaseToken();
        String ticket = WxJsUtils.getJsTicket(token);
        if(StringUtils.isNotBlank(ticket)){
            return new JsonReaderResponse().addExtra(WxJsUtils.getJsInfo(appId,ticket,url+"?token="+vr_token));
        }
        return new JsonReaderResponse();
    }
}
